package com.jcfk.eam.controller.main;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.eam.domain.query.main.EamRepairOrderExecuteFileQuery;
import com.jcfk.eam.domain.dto.main.EamRepairOrderExecuteFileDTO;
import com.jcfk.eam.service.main.EamRepairOrderExecuteFileService;

/**
 * 维修单附件
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-09-06
 */
@Api(tags = {"维修单附件管理(废弃)"})
@RestController
@RequestMapping("eamrepairorderexecutefile")
public class EamRepairOrderExecuteFileController {
    @Autowired
    private EamRepairOrderExecuteFileService eamRepairOrderExecuteFileService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamRepairOrderExecuteFileQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询维修单附件")
    @PostMapping("/queryByPage")
    public RetPage<EamRepairOrderExecuteFileDTO> queryByPage(@RequestBody ReqPageParam<EamRepairOrderExecuteFileQuery> requestParam) {
        DataPage<EamRepairOrderExecuteFileDTO> page = new DataPage<EamRepairOrderExecuteFileDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamRepairOrderExecuteFileDTO.class);
        page = eamRepairOrderExecuteFileService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  维修单附件
     * 根据id 查询详情
     */
    @ApiOperation("查询维修单附件")
    @GetMapping("/get/{id}")
    public RetResult<EamRepairOrderExecuteFileDTO> get(@PathVariable("id") String id) {
            EamRepairOrderExecuteFileDTO item = eamRepairOrderExecuteFileService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理维修单附件
     */
    @ApiOperation("保存维修单附件")
    @PostMapping("/save")
    @RequestLogHeader(modular = "维修单附件管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamRepairOrderExecuteFileDTO eamRepairOrderExecuteFile) {
        // 数据校验
        RetResult ret = eamRepairOrderExecuteFileService.isValid(eamRepairOrderExecuteFile);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamRepairOrderExecuteFile.getId())){
            // 新增
            eamRepairOrderExecuteFileService.insert(eamRepairOrderExecuteFile);
        } else{
            // 更新
            eamRepairOrderExecuteFileService.update(eamRepairOrderExecuteFile);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除维修单附件
     */
    @ApiOperation("批量删除维修单附件")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "维修单附件管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamRepairOrderExecuteFileDTO eamRepairOrderExecuteFile) {
        return RetResult.ok(eamRepairOrderExecuteFileService.logicDeleteList(eamRepairOrderExecuteFile));
    }





    /**
     *  删除维修单附件
     */
    @ApiOperation("删除维修单附件")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "维修单附件管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamRepairOrderExecuteFileService.deleteItem(id);
        return RetResult.ok();
    }
}
